//
//  CustomView.m
//  绘制弧形进度条
//
//  Created by 伍银荣 on 2021/7/1.
//  Copyright © 2021 com.example. All rights reserved.
//

#import "CustomView.h"

@interface CustomView ()
@property (strong, nonatomic) IBOutlet UILabel *propressLabel;
@end

@implementation CustomView

-(void)setProgressValue:(CGFloat)progressValue {
    _progressValue = progressValue;
    NSLog(@"_progressValue = %f",_progressValue);
    //在字符串中:一个百分号%等价于@"%%"  (%% = @"%")
    //.2f:保留浮点数小数点后两位
    _propressLabel.text = [NSString stringWithFormat:@"%.2f%%",_progressValue * 100];
    [self setNeedsDisplay];
}



// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    NSLog(@"----%f",_progressValue);
    // Drawing code
//    CGContextRef ctx = UIGraphicsGetCurrentContext();
//    CGContextAddArc(ctx, 175, 175,  100, 0 - M_PI_2, M_PI * 2 * _progressValue - M_PI_2, YES);
//    CGContextAddLineToPoint(ctx, 175, 175);
//    [[UIColor redColor] set];
//    CGContextFillPath(ctx);

    
    UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:CGPointMake(175, 175) radius:100 startAngle:0 - M_PI_2 endAngle:M_PI * 2 * _progressValue - M_PI_2 clockwise:YES];
    [path addLineToPoint:CGPointMake(175, 175)];
    [[UIColor redColor] set];
    [path fill];
}


@end
